<template>
  <div id="upload">
    <h1>Upload</h1>
    <input type="text" placeholder="标题" v-model="title" />
    <input type="text" placeholder="描述" v-model="description" />
    <mavon-editor v-model="md" :boxShadow="false" @save="upload" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      title: "",
      md: "",
      description: "",
    };
  },
  methods: {
    upload() {
      if (this.$store.state.isLogin) {
        console.log("baocun");
        this.axios
          .post(
            "/article/upload",
            this.qs.stringify({
              uname: this.$store.state.uname,
              title: this.title,
              md: this.md,
              description: this.description,
            })
          )
          .then((res) => {
            console.log(res);
            if ((res.data.code = 202)) {
              this.$router.push("/");
              alert("上传成功");
            }
          });
      } else {
        alert("请先登录");
      }
    },
  },
};
</script>

<style>
#upload {
  max-width: 1000px;
  margin: 0 auto;
}
</style>
